package Trade
{
	import mx.collections.ArrayCollection;
	import mx.controls.Alert;
	
	public class TradeFun
	{
		public function TradeFun()
		{
		}
		
		public var afterCountArr:ArrayCollection = new ArrayCollection([{"data":3},{"data":5},{"data":10},{"data":20},{"data":50}]);
		//生成追号列表 size:要生成的期数 count:注数 numberIds:起始期号 amount:投注单价 multiple:倍数,1-平倍,2-翻倍
		public function getAfterBetList(size:int, count:int, numberIds:String, singleAmount:Number=0, multiple:int=1,
			lotteryId:int=8):ArrayCollection{
			var max:String = "120";
			var maxN:int = 120;
			if(lotteryId == 9 || lotteryId == 10 || lotteryId == 11){
				max = "084"; 
				maxN = 84;
			}else if(lotteryId == 12){
				max = "096"; 
				maxN = 96;
			}else if(lotteryId == 14 || lotteryId == 15){
				max = "9999999";
				maxN = 9999999;
			}
			max = numberIds.substring(0,numberIds.length-3) + max;
			var maxNid = Number(max);
			var arr:ArrayCollection = new ArrayCollection();
			var numberId:Number = Number(numberIds);
			for(var i:int=0; i<size; i++){
				var obj:Object = new Object();
				obj.id = i+1;
				obj.numberId = numberId;
				if(numberId > maxNid){
					continue; //追号超过最大数，禁止本轮追号
					numberId = numberId - maxN;
				}
				obj.numberId = numberId;
				obj.singleAmount = singleAmount;
				obj.amount = singleAmount*count;
				obj.deadline = "2012-08-12 22:00:10";
				obj.count = count; //注数
				obj.checked = true; //是否选择
				singleAmount = singleAmount*multiple;
				arr.addItem(obj);
				numberId++;
			}
			return arr;
		}
		//检查位数
		public function checkLength(str:String, length:int){
			if(str.length==length)
				return true;
			Alert.show(str+":"+str.length);
			return false;
		}
		
		//是否是3D或P3玩法
		public function is3DorP3(lotteryName:String):Boolean{
			if(lotteryName.indexOf("3D")>=0 || lotteryName.indexOf("P3")>=0){
				return true;
			}
			return false;
		}
		//校验单式
		//ltName:lotteryName
		public function verifyDanNumbers(betwayS:Object, numberArr:Array,ltName:String="时时彩"):Boolean{
				var i:int = 0;
				if(betwayS == null){
					Alert.show("未选择投注方式!");
					return false;
				}
				if(numberArr==null || numberArr.length==0){
					Alert.show("未填写投注号码!");
					return false;
				}
				var bname:String = betwayS.name;
				var bname2:String = "";
				if(is3DorP3(ltName)){ //3D或P3
					switch(bname){
						case "复式" : bname2="三星";break;
						case "单式" : bname2="三星单式";break;
					}
				}
				if(bname.indexOf("五星")>=0){
					for(i=0; i<numberArr.length; i++){
						if(!checkLength(String(numberArr[i]), 5)){
							Alert.show("投注号码填写不正确！");
							return false;
						}
					}
				}else if(bname.indexOf("四星")>=0){
					for(i=0; i<numberArr.length; i++){
						if(!checkLength(String(numberArr[i]), 4)){
							Alert.show("投注号码填写不正确！");
							return false;
						}
					}
				}else if(bname.indexOf("三星")>=0 || bname2.indexOf("三星")>=0){
					for(i=0; i<numberArr.length; i++){
						if(!checkLength(String(numberArr[i]), 3)){
							Alert.show("投注号码填写不正确！");
							return false;
						}
					}
				}else if(bname.indexOf("二星")>=0 || bname2.indexOf("二星")>=0){
					//Alert.show(bname);
					for(i=0; i<numberArr.length; i++){
						if(!checkLength(String(numberArr[i]), 2)){
							Alert.show("投注号码填写不正确！");
							return false;
						}
					}
				}
				return true;
			}
	}
}